import React, { Component } from 'react'
import { ListBox } from '../../../components'
import { fetchData } from '../../../components/AjaxConsumer'

import { Button, Modal, Form, Input, Radio, Upload, Icon } from 'antd';
export default class ListRawContractChangePage extends Component {
    constructor(props) {
        super(props);
        this.state = {
            tableColumn: {},
            searchComponentData: [],
            visible: false,
        };
        //行操作列表
        this.rowOperation = [

        ];
        //header 操作列表
        this.headerOperation = [
            {
                handleName: 'export',
                showName: 'Excel',
                iconClass: 'file-excel'
            }
        ];

        //table列表展示列配置
        //showName、columnName 必有属性， columnWidth 可选，默认100, columnHidden: true 列隐藏
        this.tableColumn = {
            storageKey: 'listSellPage',
            data: [
               {
                    showName: '条码',
                    columnName: 'barcode',
                    columnWidth: 140
                }, {
                    showName: '原合同号',
                    columnName: 'contractNoOld',
                    columnWidth: 140
                }, {
                    showName: '新合同号',
                    columnName: 'contractNoNew',
                    columnWidth: 140
                }, {
                    showName: '型号',
                    columnName: 'model'
                }, {
                    showName: '型号描述',
                    columnName: 'modelDesc'
                }, {
                    showName: '型号类型',
                    columnName: 'modelType'
                },{
                    showName: '单位',
                    columnName: 'unit'
                },{
                    showName: '长度',
                    columnName: 'amount'
                }, {
                    showName: '库位',
                    columnName: 'wlCode'
                }, {
                    showName: '修改人',
                    columnName: 'createBy'
                }, {
                    showName: '修改时间',
                    columnName: 'gmtCreate',
                    columnWidth: 180
                }

            ]
        };

        //搜索属性配置
        this.searchComponentData = [
            
            {
                showName: '型号类型',
                name: 'modelType',
                type: 'select',
                optionList:[
                ]
            },{
                  name: 'gmtCreate',
                  type: 'date',
                  maxName: 'gmtCreateMax',
                  minName: 'gmtCreateMin'
              },{
                
                  name: 'amount',
                  type: 'number',
                  maxName: 'amountMax',
                  minName: 'amountMin'
              }
        ];

    }

    rowHandles = (strHandles, rowObj) => {
        if (strHandles == 'export') {
            this.exportXlsHandle(rowObj);
        }
    }

    exportXlsHandle = (conditonData) => {
        console.log('-------导出条件--------', conditonData);
        let param = '?'
        for (let key in conditonData) {
            if (conditonData[key] != '') {
                console.log(key, conditonData[key]);
                param = param + key + '=' + conditonData[key] + '&'
            }
        }
        console.log(param);
        window.location.href = '/material/rawContractChange/listExp' + param;
    }

    //刷新列表
    refreshHandle = () => {
        this.refs.listWorkarea.refreshHandle();
    }
    componentWillMount() {
        const dicType = 'model_type';
        const options= {
            url: '/base/dic/get/' + dicType,
            type: 'get',
            condition:{}
        };
        //型号类型select
        fetchData(this, options, this.dicInitCallBackHandle);
    }

    //下拉框 初始化
    dicInitCallBackHandle = (resData)=>{
        let optionList = [];
        let tmp = {};
        tmp.optionKey = '';
        tmp.optionShow = '';
        optionList.push(tmp);
        resData.data.map( (e,index) => {
            let tmp = {};
            tmp.optionKey = e.dicCode;
            tmp.optionShow = e.dicName;
            optionList.push(tmp);
        });
        this.tableColumn.data[5].showOption = optionList;
        this.searchComponentData[0].optionList = optionList;
    }




    render() {
        //当左侧隐藏时，列表宽度加上左侧的宽度，
        //1、当前this.props.isHideLeft 是从页面组件containers/Main/main.js传过来
        //2、this.props.isHideLeft 最顶级赋值是在页面 containers/Main/main.js
        let isHideLeft = this.props.isHideLeft;

        return (
            <div>
                <ListBox
                    ref='ListRawContractChangePage'
                    title="原材料合同变更查询"
                    isHideLeft={isHideLeft}
                    tableColumnData={this.tableColumn}
                    searchComponentData={this.searchComponentData}
                    url='/material/rawContractChange/list'
                    rowHandles={this.rowHandles}
                    rowOperation={this.rowOperation}
                    headerOperation={this.headerOperation}
                    isRowSingle={true}
                />
            </div>
        )
    }
}
